﻿Public Class BenachrichtigungForm
    Inherits WeifenLuo.WinFormsUI.Docking.DockContent
    Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions


    Private _benachrichtigungen As List(Of LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung)


    Private _benaManager As LibMultiPlug.Core.Benachrichtigungen.BenachrichtigungsManager


    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

        _benaManager = LibMultiPlug.Core.Benachrichtigungen.BenachrichtigungsManager.GetInstance()

        AddHandler _benaManager.BenachrichtigungAdded, _
                    Sub(message As LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung)
                        Call InternalInitialize()
                    End Sub

        AddHandler _benaManager.BenachrichtigungRemoved, _
                    Sub(message As LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung)
                        Call InternalInitialize()
                    End Sub

        Call InternalInitialize()

    End Sub

    Private Sub InternalInitialize()

        lvBenachrichtigungen.Items.Clear()

        _benachrichtigungen = LibMultiPlug.Core.Services.ServiceManager.GetInstance() _
            .GetBenachrichtigungsService().GetBenachrichtigungen()

        For Each b As LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung In _benachrichtigungen

            Dim lvi As ListViewItem = lvBenachrichtigungen.Items.Add(b.Datum.ToString())
            lvi.SubItems.Add(b.Info)
            lvi.SubItems.Add(b.Modul)

        Next

    End Sub

    Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvBenachrichtigungen.MouseDoubleClick

        If lvBenachrichtigungen.SelectedIndices.Count > 0 Then

            _benachrichtigungen(lvBenachrichtigungen.SelectedIndices(0)).Action()

        End If

    End Sub

    Public Sub Delete() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Delete

        If lvBenachrichtigungen.SelectedIndices.Count > 0 Then _
            _benaManager.DeleteBenachrichtigung(_benachrichtigungen(lvBenachrichtigungen.SelectedIndices(0))) _
          : RaiseEvent OptionsChanged(Me, Nothing)

    End Sub

    Public Sub [New]() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.New
        Throw New NotImplementedException()
    End Sub

    Public Sub Open() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Open
        _benachrichtigungen(lvBenachrichtigungen.SelectedIndices(0)).Action()
    End Sub

    Public Event OptionsChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.OptionsChanged

    Public Sub PagePreview() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.PagePreview
        Throw New NotImplementedException()
    End Sub

    Public Sub Print() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Print
        Throw New NotImplementedException()
    End Sub

    Public Shadows Sub Refresh() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Refresh

        Call InternalInitialize()

        MyBase.Refresh()

        RaiseEvent OptionsChanged(Me, Nothing)

    End Sub

    Public Sub Save() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Save
        Throw New NotImplementedException()
    End Sub

    Public Sub SaveAs() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SaveAs
        Throw New NotImplementedException()
    End Sub

    Public ReadOnly Property SetDelete As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetDelete
        Get
            Return (lvBenachrichtigungen.SelectedIndices.Count > 0)
        End Get
    End Property

    Public ReadOnly Property SetNew As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetNew
        Get
            Return False
        End Get
    End Property

    Public ReadOnly Property SetOpen As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetOpen
        Get
            Return (lvBenachrichtigungen.SelectedIndices.Count > 0)
        End Get
    End Property

    Public ReadOnly Property SetPagePreview As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetPagePreview
        Get
            Return False
        End Get
    End Property

    Public ReadOnly Property SetPrint As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetPrint
        Get
            Return False
        End Get
    End Property

    Public ReadOnly Property SetRefresh As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetRefresh
        Get
            Return True
        End Get
    End Property

    Public ReadOnly Property SetSave As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetSave
        Get
            Return False
        End Get
    End Property

    Public ReadOnly Property SetSaveAs As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetSaveAs
        Get
            Return False
        End Get
    End Property

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvBenachrichtigungen.SelectedIndexChanged
        RaiseEvent OptionsChanged(Me, Nothing)
    End Sub

    Public ReadOnly Property SetCoopDesign As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetCoopDesign
        Get
            Return True
        End Get
    End Property
End Class